// components/common/apply-audit-item/index.js
import componentBehavior from '../../../behaviors/component';
import { COMPONENT_OPTIONS } from '../../../constants/common';
import { SPOKESMAN_APPLY_FIELD, DISTRIBUTOR_APPLY_FIELD, APPLY_AUDIT_RESULT, APPLY_AUDIT_RESULT_VALUE } from '../../../constants/manage';
import { getPicFullPath } from '../../../common/utils';

Component({
    behaviors: [componentBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        type: {
            type: String,
            value: '', // spokesman 代言人 | distributor  分销员
        },
        applyInfo: {
            type: Object,
            value: {},
        },
    },
    observers: {
        'type': function(type) {
            const applyFieldMap = type === 'spokesman' ? SPOKESMAN_APPLY_FIELD : DISTRIBUTOR_APPLY_FIELD;
            this.setData({ applyFieldMap });
        },
        'applyInfo': function(val) {
            this.setData({ avatarUrl: getPicFullPath(val.avatar) });
        },
    },
    data: {
        avatarUrl: '',
        applyFieldMap: {},
        APPLY_AUDIT_RESULT,
        APPLY_AUDIT_RESULT_VALUE,
    },
    methods: {
        handleAgree() {
            this.triggerEvent('agree', this.data.applyInfo.id);
        },
        handleDisagree(e) {
            this.triggerEvent('disagree', this.data.applyInfo.id);
        },
    }
})
